function changeMenu(menuflag) {
	var pageid;
	for(var i = 1; i <= 5; i++) {
		pageid = 'page' + i;
		if(menuflag == i) {
			document.getElementById(pageid).style.color = '#FF9C00';
			document.getElementById(pageid).style.borderBottom = '2px solid #FF9C00';
		} else {
			document.getElementById(pageid).style.color = '#333333';
			document.getElementById(pageid).style.borderBottom = 'none';
		}
	}
}

function gotoPage(index) {
	if(index == 1) {
		window.location = '../pages/index.html';
	} else if(index == 2) {
		window.location = '../pages/qgxf.html';
	} else if(index == 3) {
		setCookie('kdcurcityId', 123);
		setCookie('kdcurcityName', '海外置业');
		window.location = '../pages/hwzy.html';
	} else if(index == 4) {
		window.location = '../pages/kdzf.html';
	}
	else if(index == 5) {
		window.location = '../pages/page1.html';
	}
}

function timestampToTime(timestamp) {
	var date = new Date(timestamp * 1000);
	var Y = date.getFullYear() + '-';
	var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
	var D = date.getDate() + ' ';
	var h = date.getHours() + ':';
	var m = date.getMinutes() + ':';
	var s = date.getSeconds();
	return Y + M + D;
	//  return Y+"年"+M+"月"+D+"日";
}

function getQueryString(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
	var r = window.location.search.substr(1).match(reg);
	if(r != null) return unescape(r[2]);
	return null;
}

function getParameter(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
	var r = decodeURIComponent(window.location.search).substr(1).match(reg);
	if(r != null) return unescape(r[2]);
	return null;
}

var compare = function(prop) {
	return function(obj1, obj2) {
		var val1 = obj1[prop];
		var val2 = obj2[prop];
		if(val1 < val2) {
			return -1;
		} else if(val1 > val2) {
			return 1;
		} else {
			return 0;
		}
	}
}

function setCookie(name, value) {
	var Days = 30;
	var exp = new Date();
	exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
	document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}

//读取cookies 
function getCookie(name) {
	var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");

	if(arr = document.cookie.match(reg))
		return unescape(arr[2]);
	else
		return null;
}

if(!getCookie('kdcurcityId')) {
	setCookie('kdcurcityId', 0);
	setCookie('kdcurcityName', '不限');
}

var publicUrl = 'http://139.196.168.158';
var LocalImgUrl = 'http://139.196.168.158:81'; //'http://www.jubenxiong.com';
var ServerImgUrl = 'http://139.196.168.158:81';
//http://139.196.168.158:81/
function loadUserInfo(backfun) {
	//ES5不允许默认参数
	var cuid = arguments[1] || 11;
	var urlstr = publicUrl + '/v1/wx-user/get-user-info';
	jQuery.get(urlstr, {
		uid: cuid
	}, function(res) {

		var str = JSON.stringify(res.data);
		setCookie('userinfo', str);
		if(backfun) {
			backfun();
		}
	});
}

function getUserInfo() {
	var userinfos = getCookie('userinfo');
	if(!userinfos) {
		return null;
	}
	var obj = JSON.parse(getCookie('userinfo'));
	return obj;
}

function Userloginout() {
	setCookie('userinfo', '');
}

function notLogin() {
	var uinfo = getUserInfo();
	if(!uinfo) {
		window.location.href = '../pages/index.html?logout=1';
	}
}

//var obj = { Hellow:'world' }; 
//var str = JSON.stringify(obj); 
////存入 
//sessionStorage.obj = str; 
////读取 
//str = sessionStorage.obj; 
////重新转换为对象 
//obj = JSON.parse(str);

function getUserLocation(address) {
	var urlstr = 'http://api.map.baidu.com/geocoder/v2/?ak=pbmOo1GbhV3OpnvT06G4gla3hraVKTIz'
	+ '&callback=getUserLocationCallBack&output=json&address='+address;
	jQuery.getScript(urlstr);
}

function getUserLocationCallBack(res) {
	console.log('call Back');
	console.log(res);
	var lng = parseFloat(res.result.location.lng);
	var lat = parseFloat(res.result.location.lat);
	point = new BMap.Point(lng, lat);
	searchSthing('公交');
	console.log('address------');
}

function toWxUserInfo(){
	window.location.href = 'https://open.weixin.qq.com/connect/qrconnect?appid=wxfdefa90eed5ecde5&redirect_uri=http://pocket.all-star.top/kdpc/pages/index.html&response_type=code&scope=snsapi_login&state=0';
}

function toWxUserInfoByPhone(phones){
	setCookie('ph_newphone',phones);
	window.location.href = 'https://open.weixin.qq.com/connect/qrconnect?appid=wxfdefa90eed5ecde5&redirect_uri=http://pocket.all-star.top/kdpc/pages/SignLogin.html&response_type=code&scope=snsapi_login&state=0';
}